package com.ykt.converter;

import com.ykt.common.utils.ModelUtil;
import com.ykt.common.utils.UB;
import com.ykt.model.Market;
import com.ykt.vo.MarketVo;

import java.util.ArrayList;
import java.util.List;

/**
 * @author long.hua
 * @version 1.0.0
 * @since 2016-05-25 00:21
 */
public class MarketConverter {


    public static MarketVo convert(Market model){
        if(model == null){
            return null;
        }

        MarketVo vo = new MarketVo();

        vo.setId(model.getId());
        vo.setName(model.getName());
        vo.setSummary(model.getStr(Market.summary));
        vo.setProvinceId(UB.i(model.get(Market.province_id)));
        vo.setCityId(UB.i(model.get(Market.cityId)));
        vo.setDistrictId(UB.i(model.get(Market.district_id)));
        vo.setAddress(model.getStr(Market.address));
        vo.setLogo(model.getStr(Market.logo));
        vo.setPhone(model.getStr(Market.phone));
        vo.setLatitude(ModelUtil.d(model, Market.latitude));
        vo.setLongitude(ModelUtil.d(model, Market.longitude));

        return vo;
    }

    public static List<MarketVo> convert(List<Market> models){
        List<MarketVo> vos = new ArrayList<>();
        if(models == null || models.isEmpty()){
            return vos;
        }

        for (Market model : models) {
            if(model != null){
                vos.add(convert(model));
            }
        }

        return vos;
    }

}
